#include <bits/stdc++.h>
using namespace std;
struct node {
    int x,y;
    int cnt;
    node(int a, int b, int c) {x=a; y=b; cnt=c;}
    node() {}
    bool operator < (const node& a) const {
        if (x != a.x) return x < a.x;
        return y < a.y;
    }
    bool operator == (const node& a) const {
        return (x==a.x) && (y==a.y);
    }
};
set<node> s1,s2;


int main() {
    int n,k;
    int x,y;
    node t;
    int T;
    cin>>T;
    while (T--) {
        scanf("%d", &n);
        int res = 0;
        s1.clear(); s2.clear();
        for (int i=0; i<n; ++i) {
            s2.clear();
            scanf("%d", &k);
            while (k--) {
                scanf("%d %d", &x, &y);
                t.x = x; t.y = y; t.cnt = 1;
                if (s1.count(t)) {
                    set<node>::iterator tt = s1.find(t);
                    t.cnt = (tt->cnt) + 1;
                    if (t.cnt > res) res = t.cnt;
                }
                s2.insert(t);
            }
            swap(s1, s2);
        }
        if (res==1) printf("0\n");
        else printf("%d\n", res);
    }
    return 0;
}
